﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Reflection;

namespace SSPharma.Utility.Filter
{
    public class MultiValueFilter : FilterBase
    {
        #region Variables

        private PropertyInfo _propertyInfo;
        ObservableCollection<CheckedListItem<string>> _filterList = new ObservableCollection<CheckedListItem<string>>();

        #endregion

        #region Constructor

        public MultiValueFilter(PropertyInfo pi)
        {
            _propertyInfo = pi;
        }

        #endregion

        #region Properties

        public ObservableCollection<CheckedListItem<string>> FilterList
        {
            get { return _filterList; }
            set { _filterList = value; }
        }

        #endregion

        #region pulbic methods

        public override bool IsMatch(object target)
        {
            object value = _propertyInfo.GetValue(this, null);
            if (value == null)
                return false;

            int count = FilterList.Where(item => item.IsChecked).Count(item => item.Item == value.ToString());

            if (count > 0)
                return true;
            else return false;
        }

        #endregion

    }
}
